﻿package mortal.game.view.daily.render
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import fl.data.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.guide.*;
    import mortal.game.view.copy.escort.renderer.*;
    import mortal.game.view.daily.*;
    import mortal.mvc.core.*;

    public class DailyVitalityShowViewRenderer extends GCellRenderer
    {
        private var _bg:GBitmap;
        private var _lv:BitmapNumberText;
        private var _noGet:GBitmap;
        private var _get:GBitmap;
        private var _itemReward:GTileList;
        private var _canGetBitmap:GBitmap;
        private var _redPoint:GBitmap;
        private var _notOpen:GBitmap;
        public var hasReward:Boolean;

        public function DailyVitalityShowViewRenderer()
        {
            return;
        }// end function

        private function get itemData() : TActivityConfig
        {
            return _data as TActivityConfig;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this.hasReward = false;
            if (this.itemData.activity <= GameConst.TTodayAddActicvityMaxValue)
            {
                this._notOpen.visible = false;
                this.filters = null;
                this.hasReward = false;
                this._lv.text = this.itemData.activity.toString();
                this._itemReward.dataProvider = new DataProvider(DailyUtil.getGiftReward(this.itemData.activityReward, "&", "#"));
                this._itemReward.drawNow();
                if (Cache.instance.daily.data.level >= this.itemData.id)
                {
                    this._get.visible = true;
                    this._noGet.visible = false;
                    this._canGetBitmap.visible = false;
                    this.filters = [FilterConst.colorFilter];
                    this.hasReward = false;
                    EffectManager.glowFilterUnReg(this._bg);
                }
                else
                {
                    if (AutoGuideRedPoint.instance.getValueByName(AutoGuideRedPoint.DailyVitalityAdd) && Cache.instance.daily.data.activity >= this.itemData.activity)
                    {
                    }
                    this._noGet.visible = true;
                    this._get.visible = false;
                    this.filters = null;
                    if (Cache.instance.daily.data.activity >= this.itemData.activity)
                    {
                        this._canGetBitmap.visible = true;
                        this.hasReward = true;
                    }
                    else
                    {
                        this._canGetBitmap.visible = false;
                        this.hasReward = false;
                    }
                }
            }
            else
            {
                this._lv.text = "";
                this._itemReward.dataProvider = new DataProvider([]);
                this._itemReward.drawNow();
                this._notOpen.visible = true;
                this._get.visible = false;
                this._noGet.visible = false;
                this._canGetBitmap.visible = false;
                DisplayUtil.removeMe(this._redPoint);
                EffectManager.glowFilterUnReg(this._bg);
                this.filters = [FilterConst.colorFilter];
                this.hasReward = false;
            }
            return;
        }// end function

        private function onRewardGetSucceed(param1:Object) : void
        {
            var _loc_2:int = 0;
            var _loc_3:BgItemCellRenderer = null;
            var _loc_4:int = 0;
            if (this.itemData.id > Cache.instance.daily.data.level && Cache.instance.daily.data.activity >= this.itemData.activity)
            {
                _loc_2 = this._itemReward.dataProvider.length;
                _loc_4 = 0;
                while (_loc_4 < _loc_2)
                {
                    
                    _loc_3 = this._itemReward.itemToCellRenderer(this._itemReward.dataProvider.getItemAt(_loc_4)) as BgItemCellRenderer;
                    FlyToNavbarTool.flyBitmapOriginalToPack(_loc_3.itemBitmapData, _loc_3.localToGlobal(new Point(_loc_3.x, _loc_3.y)));
                    _loc_4++;
                }
            }
            return;
        }// end function

        private function onResCompl() : void
        {
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyVitalityCellBg);
            this._noGet.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyTxt10);
            this._get.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyTxt3);
            this._canGetBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyTxt13);
            this._notOpen.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyTxt14);
            this.addChild(this._itemReward);
            this.addChild(this._noGet);
            this.addChild(this._get);
            this.addChild(this._lv);
            this.addChild(this._canGetBitmap);
            this.addChild(this._notOpen);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gBitmap("", 1, 1, this);
            this._lv = UIFactory.bitmapNumberText(56, 1, "DailyNormalNum.png", 19, 20, -9, null, 9);
            this._noGet = UIFactory.gBitmap("", 86, 1);
            this._get = UIFactory.gBitmap("", 86, 1);
            this._canGetBitmap = UIFactory.gBitmap("", 3, 3);
            this._notOpen = UIFactory.gBitmap("", 31, 35);
            this._itemReward = UIFactory.tileList(31, 29, 280, 50);
            this._itemReward.setStyle("cellRenderer", BgItemCellRenderer);
            this._itemReward.columnWidth = 45;
            this._itemReward.rowHeight = 45;
            this._itemReward.selectable = false;
            this._itemReward.direction = GBoxDirection.HORIZONTAL;
            this._redPoint = UIFactory.gBitmap(ImagesConst.SmallRedPoint, 176, 2);
            NetDispatcher.addCmdListener(ServerCommand.DailyRewardGetSucceed, this.onRewardGetSucceed);
            LoaderHelp.addResCallBack(ResFileConst.daily, this.onResCompl);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            LoaderHelp.removeResEvent(ResFileConst.daily, this.onResCompl);
            EffectManager.glowFilterUnReg(this._bg);
            this._bg.dispose(param1);
            this._lv.dispose(param1);
            this._get.dispose(param1);
            this._noGet.dispose(param1);
            this._itemReward.dispose(param1);
            this._redPoint.dispose(param1);
            this._canGetBitmap.dispose(param1);
            this._notOpen.dispose(param1);
            return;
        }// end function

    }
}
